package lanQiaoBei.基础算法.前缀和;

import java.io.*;

/*
 * 二维前缀和——
 * 输入n,m（0-1000）
 * 输入整数数列
 * 输入1组数据
 * x1,y1,x2,y2询问子矩阵的和
 * */
public class P2 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static int N = 1010;
    static int n, m;
    static int[][] a = new int[N][N];
    static int[][] s = new int[N][N];

    public static void main(String[] args) throws Exception {
        scan();
        String[] ss = br.readLine().split(" ");
        int x1 = Integer.parseInt(ss[0]), y1 = Integer.parseInt(ss[1]), x2 = Integer.parseInt(ss[2]), y2 = Integer.parseInt(ss[3]);
        System.out.println(s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1]);
    }

    public static void scan() throws Exception {
        String[] ss = br.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        for (int i = 1; i <= n; i++) {
            ss = br.readLine().split(" ");
            for (int j = 1; j <= m; j++) {
                a[i][j] = Integer.parseInt(ss[j - 1]);
                s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]+a[i][j];
            }
        }
    }
}